package com.gt.xmall.model;

import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.ToStringBuilder;
//JPA标识
@Entity
@Table(name = "SYS_ROLE")
public class SysRole implements Serializable{

	private Long id;
    private String roleName;
    
    private Set<SysResource> sysResources = new LinkedHashSet<SysResource>(0);
     
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
	
	@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinTable(name="RES_ROLE",  joinColumns = { 
        @JoinColumn(name="ROLE_ID", updatable=false) }, inverseJoinColumns = { 
        @JoinColumn(name="RES_ID", updatable=false) })
	public Set<SysResource> getSysResources() {
		return sysResources;
	}
	public void setSysResources(Set<SysResource> sysResources) {
		this.sysResources = sysResources;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((roleName == null) ? 0 : roleName.hashCode());
		result = prime * result
				+ ((sysResources == null) ? 0 : sysResources.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SysRole other = (SysRole) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (roleName == null) {
			if (other.roleName != null)
				return false;
		} else if (!roleName.equals(other.roleName))
			return false;
		if (sysResources == null) {
			if (other.sysResources != null)
				return false;
		} else if (!sysResources.equals(other.sysResources))
			return false;
		return true;
	}
	 
	 
    
    
}
